#ifndef _PCF8563_H_
#define _PCF8563_H_

#include <Arduino.h>
#include <Wire.h>


#define SDA_PIN 4 //IIC数据引脚定义
#define SCL_PIN 5 //IIC时钟引脚定义

class PCF8563{
    public:
    void begin(); //初始化IIC引脚和时钟频率
    void init();  //PCF8563初始化为全1 定时中断全部关闭
    void write_time(u8 hour,u8 min,u8 second);  //PCF8563设置时分秒
    void write_day(u8 year,u8 month,u8 day,u8 week);  //PCF8563设置年月日周
    void read_time();  //PCF8563读取时分秒
    void read_day();  //PCF8563读取年月日周

    u8 second = 0;//秒数
    u8 min = 0;   //分钟
    u8 hour = 0;  //小时 
    u8 day = 0;   //号数
    u8 week = 0;  //周天数
    u8 month = 0; //月份
    u8 year = 0;  //年份

    private:
    void PCF_write(u8 add,u8 dat);
    u8 num_to_bcd(u8 dat);
    u8 bcd_to_num(u8 dat); 
  
};

#define slave 0x51
#define second_slave 0x02
#define min_slave 0x03
#define hour_slave 0x04
#define day_slave 0x05
#define week_slave 0x06
#define month_slave 0x07
#define year_slave 0x08
#define min_alarm_slave 0x09
#define hour_alarm_slave 0x0a
#define day_alarm_slave 0x0b
#define week_alarm_slave 0x0c
#define clock_out_slave 0x0d
#define timer_control_slave 0x0e
#define timer_slave 0x0f

// #define week_alarm_enable 0x00
// #define week_alarm_disable 0x80

// #define clock_out_enable 0x80
// #define clock_out_disable 0x00
// #define clock_out_32768Hz 0x00
// #define clock_out_1024Hz 0x01
// #define clock_out_32Hz 0x02
// #define clock_out_1Hz 0x03

// #define timer_enable 0x80
// #define timer_disable 0x00
// #define timer_4096Hz 0x00
// #define timer_64Hz 0x01
// #define timer_1Hz 0x02
// #define timer_1b60Hz 0x03

extern PCF8563 pcf;

#endif